//
//  FlowDetailViewController.m
//  NaRiLSVMT
//
//  Created by jmsre on 14-8-18.
//  Copyright (c) 2014年 helloyouth.org. All rights reserved.
//

#import "FlowDetailViewController.h"
#import "AllNodesInScrollView.h"
#import "TopLargerScreenView.h"
#import "NoticeInfoViewController.h"
#import "UIViewController+MJPopupViewController.h"
#import "PlayFlowNodesViewController.h"
#import "FlowDetailViewController+Request.h"
#import "PlayFlowNodes2ViewController.h"
#import "NRLSVMAllScreenViewController.h"
#import "NRLSVMForScreenViewController.h"
#import "TcpClient.h"
#import "MBProgressController.h"

extern  dispatch_source_t timer_playFlowScreen;
extern  BOOL    isPlayingFlag;//是否正在单次播放或者循环播放标识
//NSInteger   screenNo = 0;//每个节点中的第几个屏幕

extern  NSMutableDictionary *playButtonDic;//在流程控制界面，被点击播放的按钮


static  NSString *currentScreenId = nil;//当前屏幕的screenId和templateId
static  NSString *currentTemplateId = nil;//当前屏幕的screenId和templateId


BOOL    isFlowProjectPlay = NO;//是哪个模块进行的双击大图操作(流程控制or屏幕预览)

NSMutableArray  *nodeNameArrForProject = nil;//用于投屏前双击，的标题字符串显示
NSString    *currentNodeName = nil;//用于投屏前双击，的标题字符串显示


static  NSInteger   actionInfoIndex = 0;//交互信息index.0:显示交互信息.1:不显示交互信息.

extern BOOL    IsPopTwice;//是否需要pop两次.

//BOOL    isNodePagePlay = NO;//是否是在节点界面播放。是：YES.否：NO.

extern  BOOL    isProjectScreen;//是否拖屏了

extern  NSInteger   lastFlowNumber;//前一个处理的流程No.或者当前

extern  BOOL    isNotNeedTurnNode;//如果是本流程在播放，则需要切节点，否则不需要切节点

extern  BOOL    currentFlowIsPlaying;//是否是当前流程在播放

extern NSInteger   isCanJumptoDetailUI;//禁止快速点击流程进入节点界面


NSString    *intervalPlayTime;//播放间隔时间

@interface FlowDetailViewController ()<NoticePopupDelegate,
    AllNodesInScrollDelegate,
    TopLargerScreenViewDelegate,
    TopScreenViewDelegate>
{
    NoticeInfoViewController *noticeInfoViewController;
}
@end

@implementation FlowDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
  //  [self.navigationItem setHidesBackButton:YES];
    self.view.backgroundColor = ColorRGB(38, 139, 147);
    
    [self.cyclesPlayButton setBackgroundImage:[UIImage imageNamed:@"scan_stopplay.png"] forState:UIControlStateSelected];
    [self.oncePlayButton setBackgroundImage:[UIImage imageNamed:@"scan_stopplay.png"] forState:UIControlStateSelected];
    
    [self.noticeInfoButton setBackgroundImage:[UIImage imageNamed:@"forscreen_messageclick.png"] forState:UIControlStateSelected];
    [self.actionButton setBackgroundImage:[UIImage imageNamed:@"forscreen_talkclick.png"] forState:UIControlStateSelected];
    //播放的阴影
    self.textFiledViewonce = [[UIView alloc] initWithFrame:CGRectMake(80,5,50,30)];
    self.textFiledViewonce.backgroundColor = [UIColor grayColor];
    self.textFiledViewonce.alpha = 0.8;
    setViewCorner(self.textFiledViewonce,4);
    [self.viewOfPlay addSubview:self.textFiledViewonce];
    self.textFiledViewonce.hidden = YES;
    
    self.textFiledViewarrow = [[UIView alloc] initWithFrame:CGRectMake(80,5,50,30)];
    self.textFiledViewarrow.backgroundColor = [UIColor grayColor];
    self.textFiledViewarrow.alpha = 0.8;
    setViewCorner(self.textFiledViewarrow,4);
    [self.viewOfPlay addSubview:self.textFiledViewarrow];
    self.textFiledViewarrow.hidden = YES;
    
    
    self.viewOfInfoAndAct.hidden = YES;
    [self.viewOfPlay setFrame:CGRectMake(self.viewOfPlay.frame.origin.x+self.viewOfInfoAndAct.frame.size.width, self.viewOfPlay.frame.origin.y, self.viewOfPlay.frame.size.width, self.viewOfPlay.frame.size.height)];
    self.flowNameLab.text = self.flowName;
    self.playInterval.text = intervalPlayTime;
    
    isCanJumptoDetailUI = 0;//解锁：允许点击进入节点界面
    //加载图片的View
    TopLargerScreenView *topLargerScr = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"topLargerScr"];
    //加载下面的流程节点的View
    AllNodesInScrollView *bottomSmaPic = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"bottomSmaPic"];
    bottomSmaPic.delagateNodeForTapOrPlay = self;
    topLargerScr.delagateTopLargerForTap = self;

    NSMutableArray  *TmpViewNameArray = [NSMutableArray array];
    //取出 流程所有节点的name
    for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"])
    {
        [TmpViewNameArray addObject:[dic objectForKey:@"name"]];
    }
    
    topLargerScr.viewNameArray = [NSArray arrayWithArray:TmpViewNameArray];
    bottomSmaPic.nameArray = [NSArray arrayWithArray:TmpViewNameArray];
    
   [self.allNotesInView addSubview:bottomSmaPic];
    [self.allScreenInNote addSubview:topLargerScr];
    
    [bottomSmaPic initWithNameButtons];
    [topLargerScr initWithViews];

    
    NSNumber *numTmpFlag = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"playFlag"];
    
    if(numTmpFlag.integerValue == 0){
    /*************构造第一个节点的屏幕信息**************************/
    NSMutableArray  *arr = [NSMutableArray array];
    NSMutableArray  *arrView = [NSMutableArray array];
    for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"firstNodeData"])
    {
        [arr addObject:[dic objectForKey:@"name"]];
        [arrView addObject:[dic objectForKey:@"templateId"]];
        /*****************当前屏幕的screenId和templateId******************/
        currentScreenId = [dic objectForKey:@"screenId"];
        currentTemplateId = [dic objectForKey:@"templateId"];
        /***************************************************************/
    }
        //屏幕的名字
    self.screenNameArr = [NSMutableArray arrayWithArray:arr];
    /***********************************************************/
    
        [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"topScreenView"] removeFromSuperview];
        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"topScreenView"] = [[TopScreenView alloc] initWithFrame:CGRectMake(0, 0,5*100, 40)];
        //顶部的屏幕的按钮
        TopScreenView   *topScreenView = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"topScreenView"];
        topScreenView.delagateTopScreenForTap = self;
        topScreenView.nameArray = [NSArray arrayWithArray:arr];
        [self.allScreenTopView addSubview:topScreenView];
        [topScreenView initWithNameButtons];
    
        
        [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"] removeFromSuperview];
        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"] = [[RootScreenView alloc] initWithFrame:CGRectMake(10, 114, Screen_Width-20, 430-40)];
        
        RootScreenView *rootScreenView = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"];
        rootScreenView.viewNameArray = [NSArray arrayWithArray:arrView];
        [self.view insertSubview:rootScreenView belowSubview:self.allScreenInNote];
        [rootScreenView initWithViews:0];
    
    }
    //点击进来  播放状态
    else
    {
        
        /**********************初始化播放黄色边框************************/
        NSInteger   playNodeIndex = StringFromId(allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"havePlayNodeIndex"]).integerValue; //已经播放到第几个
        
        NSDictionary *dic = (NSDictionary *)[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeButtonArr"] objectAtIndex:playNodeIndex];
        
        //取出播放节点按钮
        UIButton *button = [dic objectForKey:@(playNodeIndex)];
        
        [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"shadowImageView"] setFrame:CGRectMake(button.frame.origin.x, button.frame.origin.y, button.frame.size.width, button.frame.size.height)];
        //判断 是 在单行   还是  双行
        if((playNodeIndex/5)%2 == 0)
        {
            if(playNodeIndex==0)
            {
                //第一个节点
                [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"shadowImageView"] setImage:[UIImage imageNamed:@"firstRow_1_2.png"]];
            }
            else
            {
                switch ((playNodeIndex+1)%5) {
                    case 0:
                    {
                        //twoRow_6_2
                        [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"shadowImageView"] setImage:[UIImage imageNamed:@"twoRow_11_2.png"]];
                    }
                        break;
                    case 1:
                    case 2:
                    case 3:
                    {
                        [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"shadowImageView"] setImage:[UIImage imageNamed:@"firstRow_234_2.png"]];
                    }
                        break;
                    case 4:
                    {
                        [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"shadowImageView"] setImage:[UIImage imageNamed:@"firstRow_5_2.png"]];
                    }
                        break;
                    default:
                        break;
                }
            }
        }
        else
        {
            switch ((playNodeIndex+1)%5) {
                case 0:
                {
                    //threeRow_11_2
                    [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"shadowImageView"] setImage:[UIImage imageNamed:@"threeRow_10_2.png"]];
                }
                    break;
                case 1:
                case 2:
                case 3:
                {
                    [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"shadowImageView"] setImage:[UIImage imageNamed:@"twoRow_987_2.png"]];
                }
                    break;
                case 4:
                {
                    [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"shadowImageView"] setImage:[UIImage imageNamed:@"twoRow_6_2.png"]];
                }                     break;
                default:
                    break;
            }
        }
        [bottomSmaPic addSubview:allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"shadowImageView"]];
        /***************************************************/
        [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"topScreenView"] removeFromSuperview];
        
        NSString *flowNodeId = [[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] objectAtIndex:playNodeIndex] objectForKey:@"id"];
        
        for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeThumbnailArr"])
        {
            if([[dic allKeys] containsObject:flowNodeId])
            {
                allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"topScreenView"] = [[TopScreenView alloc] initWithFrame:CGRectMake(0, 0,[[dic objectForKey:flowNodeId] count]*100, 40)];
                break;
            }
        }
        NSMutableArray  *arr = [NSMutableArray array];
        NSMutableArray  *arrView = [NSMutableArray array];
        for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeThumbnailArr"])
        {
            if([[dic allKeys] containsObject:flowNodeId])
            {
                for(NSDictionary *nodeDic in [dic objectForKey:flowNodeId])
                {
                    [arr addObject:[nodeDic objectForKey:@"name"]];
                    [arrView addObject:[nodeDic objectForKey:@"templateId"]];
                }
                /*****************当前屏幕的screenId和templateId******************/
                currentScreenId = [[[dic objectForKey:flowNodeId] objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]] objectForKey:@"screenId"];
                currentTemplateId = [[[dic objectForKey:flowNodeId] objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]] objectForKey:@"templateId"];
                /***********************************/
                break;
            }
        }
        
        
        self.screenNameArr = [NSMutableArray arrayWithArray:arr];
        TopScreenView   *topScreenView = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"topScreenView"];
        topScreenView.delagateTopScreenForTap = self;
        topScreenView.nameArray = [NSArray arrayWithArray:arr];
        [self.allScreenTopView addSubview:topScreenView];
        [topScreenView initWithNameButtons];
        
        /********************每个节点的屏幕s****************************/
        [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"] removeFromSuperview];
        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"] = [[RootScreenView alloc] initWithFrame:CGRectMake(10, 114,(Screen_Width-20), 430-40)];
        RootScreenView *rootScreenView = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"];
        rootScreenView.viewNameArray = [NSArray arrayWithArray:arrView];
        [self.view insertSubview:rootScreenView belowSubview:self.allScreenInNote];
        [rootScreenView initWithViews:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]];
    }
    /******************给本viewController最上层上添加一个双击手势*********************/
    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
    doubleTap.numberOfTapsRequired = 1;
    [self.allScreenInNote addGestureRecognizer:doubleTap];
    allBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    allBtn.frame = Frame(957,337,40,40);
    [allBtn setBackgroundImage:[UIImage imageNamed:@"scan_fullscreen.png"] forState:UIControlStateNormal];
    [allBtn addTarget:self action:@selector(fullScreenClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.allScreenInNote addSubview:allBtn];
    [self.allScreenInNote bringSubviewToFront:allBtn];
    
    
    /******************************节点在播放*******************************/
    
    if(numTmpFlag.integerValue != 0)
    {
        if([[playButtonDic objectForKey:@"flag"] isEqualToString:@"once"])//单次播放
        {
            UIButton *but = (UIButton *)[playButtonDic objectForKey:@"button"];
            
            if(but.selected == YES)
            {
                isPlayingFlag = YES;
                self.oncePlayButton.selected = NO;
            }
            else
            {
                allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] = @(1);
                isPlayingFlag = NO;
                self.oncePlayButton.selected = YES;
            }
            
            [self performSelector:@selector(oncePlayAction:) withObject:self.oncePlayButton];
        }
        else//循环
        {
            
            UIButton *but = (UIButton *)[playButtonDic objectForKey:@"button"];
            
            if(but.selected == YES)
            {
                isPlayingFlag = YES;
                self.cyclesPlayButton.selected = NO;
            }
            else
            {
                allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] = @(1);
                isPlayingFlag = NO;
                self.cyclesPlayButton.selected = YES;
            }
            
            [self performSelector:@selector(cyclesPlayAction:) withObject:self.cyclesPlayButton];
        }

    }
    //非播放
    else{
    //获取所有节点信息
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] enumerateObjectsUsingBlock:^(id obj,NSUInteger idx,BOOL *stop){
            __block NSDictionary *dic = (NSDictionary *)obj;
            __block NSString    *nodeId = [dic objectForKey:@"id"];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self NRLSMTGetThumbnailByFlowNodeId:nodeId];
            });
        }];
    });
    }
    
    [AddNoticeObserver(NoticeKey_BackrootView){
        [self backData];
    }];
}
-(void)viewWillAppear:(BOOL)animated
{
    if (isHaveFlowPlaying == YES)
    {
        self.playInterval.enabled = NO;
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)backData
{
    //返回流程  不是在 节点界面播放
    allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"isNodePagePlay"] = @(0);
    
    //是否有流程在播放
    for(NSDictionary *dic in allFlowDataArr)
    {
        NSEnumerator    *enuObj = [dic objectEnumerator];
        for(NSDictionary *dic2 in enuObj)
        {
            if([[dic2 objectForKey:@"playFlag"] intValue] == 1)
            {
                allFlowDataArr[isPlayingFlowNumber][isPlayingFlowId][@"isNodePagePlay"] = @(0);
            }
        }
    }
    IsPopTwice = NO;
    
    self.playInterval.enabled = NO;
    intervalPlayTime = self.playInterval.text;
    
    if([allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue] == 1 || [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue] == 0)
    {
        if ([allFlowDataArr[isPlayingFlowNumber][isPlayingFlowId][@"playFlag"] intValue] == 1)
        {
            isNotNeedTurnNode = YES;
        }
        NSMutableDictionary *playButDic = nil;
        if ([allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue] == 1)
        {
            playButDic = [NSMutableDictionary dictionaryWithDictionary:@{@"oncebutton": self.oncePlayButton,@"onceflag":@"once",@"cyclesbutton": self.cyclesPlayButton,@"cyclesflag":@"cycles"}];
            [self.delegateFlowDetail HandleNodePlayJumptoFlowPlay:self ActionButton:playButDic];
        }
        //        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"playFlag"] = @(0);
        //        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] = @(0);//这边置为0是否有问题
    }
    else
    {
        NSMutableDictionary *playButDic = nil;
        if(self.onceplayFlag)
        {
            playButDic = [NSMutableDictionary dictionaryWithDictionary:@{@"oncebutton": self.oncePlayButton,@"flag":@"once"}];
        }
        else
        {
            playButDic = [NSMutableDictionary dictionaryWithDictionary:@{@"cyclesbutton": self.cyclesPlayButton,@"flag":@"cycles"}];
        }
        
        [self.delegateFlowDetail HandleNodePlayJumptoFlowPlay:self ActionButton:playButDic];
    }
    
    //    AllNodesInScrollView *bottomSmaPic = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"bottomSmaPic"];
    //    for (UIView *v in bottomSmaPic.subviews) {
    //        if ([v isKindOfClass:[UIButton class]]) {
    //            [v removeFromSuperview];
    //        }
    //    }
    
    for(NSDictionary *dic in allFlowDataArr)
    {
        NSEnumerator *enu = [dic objectEnumerator];
        for(NSDictionary *enuDic in enu)
        {
            AllNodesInScrollView *bottomSmaPic = [enuDic objectForKey:@"bottomSmaPic"];
            for (UIView *v in bottomSmaPic.subviews) {
                if ([v isKindOfClass:[UIButton class]]) {
                    [v removeFromSuperview];
                }
            }
        }
    }

}
- (IBAction)backAction:(id)sender {
    
    //返回流程  不是在 节点界面播放
    allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"isNodePagePlay"] = @(0);
    
    //是否有流程在播放
    for(NSDictionary *dic in allFlowDataArr)
    {
        NSEnumerator    *enuObj = [dic objectEnumerator];
        for(NSDictionary *dic2 in enuObj)
        {
            if([[dic2 objectForKey:@"playFlag"] intValue] == 1)
            {
                allFlowDataArr[isPlayingFlowNumber][isPlayingFlowId][@"isNodePagePlay"] = @(0);
            }
        }
    }
    IsPopTwice = NO;
    
    self.playInterval.enabled = NO;
    intervalPlayTime = self.playInterval.text;
    
    if([allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue] == 1 || [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue] == 0)
    {
        if ([allFlowDataArr[isPlayingFlowNumber][isPlayingFlowId][@"playFlag"] intValue] == 1)
        {
            isNotNeedTurnNode = YES;
        }
        NSMutableDictionary *playButDic = nil;
        if ([allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue] == 1)
        {
            playButDic = [NSMutableDictionary dictionaryWithDictionary:@{@"oncebutton": self.oncePlayButton,@"onceflag":@"once",@"cyclesbutton": self.cyclesPlayButton,@"cyclesflag":@"cycles"}];
            [self.delegateFlowDetail HandleNodePlayJumptoFlowPlay:self ActionButton:playButDic];
        }
//        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"playFlag"] = @(0);
//        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] = @(0);//这边置为0是否有问题
    }
    else
    {
        NSMutableDictionary *playButDic = nil;
        if(self.onceplayFlag)
        {
            playButDic = [NSMutableDictionary dictionaryWithDictionary:@{@"oncebutton": self.oncePlayButton,@"flag":@"once"}];
        }
        else
        {
            playButDic = [NSMutableDictionary dictionaryWithDictionary:@{@"cyclesbutton": self.cyclesPlayButton,@"flag":@"cycles"}];
        }
        
        [self.delegateFlowDetail HandleNodePlayJumptoFlowPlay:self ActionButton:playButDic];
    }
    
//    AllNodesInScrollView *bottomSmaPic = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"bottomSmaPic"];
//    for (UIView *v in bottomSmaPic.subviews) {
//        if ([v isKindOfClass:[UIButton class]]) {
//            [v removeFromSuperview];
//        }
//    }
    
    for(NSDictionary *dic in allFlowDataArr)
    {
        NSEnumerator *enu = [dic objectEnumerator];
        for(NSDictionary *enuDic in enu)
        {
            AllNodesInScrollView *bottomSmaPic = [enuDic objectForKey:@"bottomSmaPic"];
            for (UIView *v in bottomSmaPic.subviews) {
                if ([v isKindOfClass:[UIButton class]]) {
                    [v removeFromSuperview];
                }
            }
        }
    }
    //[self dismissViewControllerAnimated:NO completion:nil];
    PostNoticeObserver(NoticeKey_ScrollViewSecond,nil);
    
}
//展开button
- (IBAction)expandAction:(id)sender {
    NSInteger num = [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] count];    if(num <= 10)
    {
        return;
    }
    
    if(self.flowDetailBottomView.frame.size.height == 240.0)
    {
        [self.expandButton setBackgroundImage:[UIImage imageNamed:@"scan_closethumb.png"] forState:UIControlStateNormal];
        [self.flowDetailBottomView setFrame:Frame(self.flowDetailBottomView.frame.Xpos, self.flowDetailBottomView.frame.Ypos-200, self.flowDetailBottomView.frame.Width, self.flowDetailBottomView.frame.Height+200)];
        [self.allNotesInView setFrame:Frame(self.allNotesInView.frame.Xpos, self.allNotesInView.frame.Ypos, self.allNotesInView.frame.Width, self.allNotesInView.frame.Height+200)];
    }
    else
    {
         [self.expandButton setBackgroundImage:[UIImage imageNamed:@"scan_openthumb.png"] forState:UIControlStateNormal];
        [self.flowDetailBottomView setFrame:Frame(self.flowDetailBottomView.frame.Xpos, self.flowDetailBottomView.frame.Ypos+200, self.flowDetailBottomView.frame.Width, self.flowDetailBottomView.frame.Height-200)];
        [self.allNotesInView setFrame:Frame(self.allNotesInView.frame.Xpos, self.allNotesInView.frame.Ypos, self.allNotesInView.frame.Width, self.allNotesInView.frame.Height-200)];
    }
}
//展开交互信息
- (IBAction)ActionOfallOper:(id)sender {
    
    UIButton *button = (UIButton *)sender;
    
    if (button.selected == NO)
    {
        button.selected = YES;
            [self.allOperButton setBackgroundImage:[UIImage imageNamed:@"allOperButtonSelected.png"] forState:UIControlStateNormal];
        [self.viewOfInfoAndAct setHidden:NO];
        [self.viewOfPlay setFrame:CGRectMake(self.viewOfPlay.frame.origin.x-self.viewOfInfoAndAct.frame.size.width, self.viewOfPlay.frame.origin.y, self.viewOfPlay.frame.size.width, self.viewOfPlay.frame.size.height)];
    }
    else
    {
        button.selected = NO;
        [self.viewOfInfoAndAct setHidden:YES];
        [self.allOperButton setBackgroundImage:[UIImage imageNamed:@"allOperButton.png"] forState:UIControlStateNormal];
        [self.viewOfPlay setFrame:CGRectMake(self.viewOfPlay.frame.origin.x+self.viewOfInfoAndAct.frame.size.width, self.viewOfPlay.frame.origin.y, self.viewOfPlay.frame.size.width, self.viewOfPlay.frame.size.height)];
        
        
        if (actionInfoIndex == 1)
        {
            [self actionInfoAction:self.actionButton];
        }
        
    }
}

- (IBAction)cyclesPlayAction:(id)sender {
    
    self.arrowplayFlag = YES;
    self.textFiledViewarrow.hidden = NO;
    
    if (isHaveFlowPlaying == YES && currentFlowIsPlaying == NO) {
        self.arrowplayFlag = NO;
        self.textFiledViewarrow.hidden = YES;
        [[MBProgressController sharedInstance] showTipsOnlyText:@"其他流程正在播放" AndDelay:1.5];
        return;
    }
    
    if ([self.playInterval.text intValue] < 5)
    {
        [[MBProgressController sharedInstance] showTipsOnlyText:@"播放间隔时间不能小于5" AndDelay:1.5];
        self.playInterval.text = @"5";
    }
   // [self.playInterval endEditing:NO];
    
    if([allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue] == 2)
    {
        self.arrowplayFlag = NO;
        self.textFiledViewarrow.hidden = YES;
        //停止单次播放
        self.oncePlayButton.selected = NO;
        [self.oncePlayButton setTitle:@"单次播放" forState:UIControlStateNormal];
        if (timer_playFlowScreen != nil) {
        dispatch_source_cancel(timer_playFlowScreen);
        }
    }
    UIButton *cyclesButton = (UIButton *)sender;
    
    allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] = @(2);
    //暂停循环播放
    if(cyclesButton.selected == YES)
    {
        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] = @(1);
        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"playFlag"] = @(0);
        isPlayingFlag = NO;
        cyclesButton.selected = NO;
       // self.playInterval.enabled = YES;
    }
    else
    {
        self.textFiledViewonce.hidden = YES;
        self.onceplayFlag = NO;
        isPlayingFlag = YES;
        cyclesButton.selected = YES;
        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"playFlag"] = @(1);
        isPlayingFlowId = currentQueryingflowId;
        isPlayingFlowNumber = lastFlowNumber;
       // self.playInterval.enabled = NO;
    }
    AllNodesInScrollView *bottomSmaPic = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"bottomSmaPic"];
    /****************将本流程数据保存用于播放*****************/
    /******************更新 allFlowDataArr*****************/
    allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"intervalTime"] = @(self.playInterval.text.integerValue);
    if([allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue] == 1  || [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"playFlag"] intValue] == 0){
        self.textFiledViewarrow.hidden = YES;
        self.arrowplayFlag = NO;
    }
    else{
        self.textFiledViewarrow.hidden = NO;
        self.arrowplayFlag = YES;
    }
    /*****************************************************/
    [bottomSmaPic onceOrcyclesPlay:allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeButtonArr"] StartIndex:StringFromId(allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"havePlayNodeIndex"]).integerValue Interval:StringFromId(allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"intervalTime"]).integerValue IsCyclesPlay:YES isPause:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue]];
}

- (IBAction)oncePlayAction:(id)sender {
    self.onceplayFlag = YES;
    self.textFiledViewonce.hidden = NO;
    if (isHaveFlowPlaying == YES && currentFlowIsPlaying == NO) {
        self.onceplayFlag = NO;
        self.textFiledViewonce.hidden = YES;
        [[MBProgressController sharedInstance] showTipsOnlyText:@"其他流程正在播放" AndDelay:1.5];
        return;
    }
    if ([self.playInterval.text intValue] < 5)
    {
        [[MBProgressController sharedInstance] showTipsOnlyText:@"播放间隔时间不能小于5" AndDelay:1.5];
        self.playInterval.text = @"5";
    }
    [self.playInterval endEditing:NO];
    
    if([allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue] == 2)
    {
//        return;
        self.onceplayFlag = NO;
        self.textFiledViewonce.hidden = YES;
        self.cyclesPlayButton.selected = NO;
        [self.cyclesPlayButton setTitle:@"循环播放" forState:UIControlStateNormal];
        if (timer_playFlowScreen != nil) {
        dispatch_source_cancel(timer_playFlowScreen);
        }
    }
    
    UIButton *onceButton = (UIButton *)sender;
    
    allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] = @(2);
    if(onceButton.selected == YES)
    {
        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] = @(1);
        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"playFlag"] = @(0);
        isPlayingFlag = NO;
        onceButton.selected = NO;
        self.playInterval.enabled = YES;
    }
    else
    {
        isPlayingFlag = YES;
        onceButton.selected = YES;
        allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"playFlag"] = @(1);
        isPlayingFlowId = currentQueryingflowId;
        isPlayingFlowNumber = lastFlowNumber;
        self.playInterval.enabled = NO;
        self.textFiledViewarrow.hidden = YES;
        self.arrowplayFlag = NO;
    }
    [self.oncePlayButton setTitle:@"暂停" forState:UIControlStateSelected];
    [self.oncePlayButton setTitle:@"单次播放" forState:UIControlStateNormal];
    
    
    AllNodesInScrollView *bottomSmaPic = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"bottomSmaPic"];
    /****************将本流程数据保存用于播放*****************/
    /******************更新 allFlowDataArr*****************/
    allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"intervalTime"] = @(self.playInterval.text.integerValue);
    
    if([allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue] == 1 ||
       [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"playFlag"] intValue] == 0){
        self.textFiledViewonce.hidden = YES;
        self.onceplayFlag = NO;
    }
    else{
        self.textFiledViewonce.hidden = NO;
        self.onceplayFlag = YES;
    }
    
    /*****************************************************/
    [bottomSmaPic onceOrcyclesPlay:allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeButtonArr"] StartIndex:StringFromId(allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"havePlayNodeIndex"]).integerValue Interval:StringFromId(allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"intervalTime"]).integerValue IsCyclesPlay:NO isPause:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"pauseFlag"] intValue]];
}

- (IBAction)noticeInfoAction:(id)sender {
    if ([allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"playFlag"] integerValue] == 1) {
        [[MBProgressController sharedInstance] showTipsOnlyText:@"流程正在播放" AndDelay:1.5];
        return;
    }
    
    NSString *flowNodeId = [[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] objectAtIndex:StringFromId(allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"haveChooseNodeIndex"]).integerValue] objectForKey:@"id"];
    NSMutableDictionary *nodeDic = [NSMutableDictionary dictionary];
    for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeThumbnailArr"])
    {
        if([[dic allKeys] containsObject:flowNodeId])
        {
            nodeDic = [[dic objectForKey:flowNodeId] objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]];
            break;
        }
    }
    if([nodeDic[@"hostId"] isEqualToString:@""])
    {
        [[MBProgressController sharedInstance] showTipsOnlyText:@"画面未启动" AndDelay:1.5];
        return;
    }
    
    NSString *title = nodeDic[@"name"];
    
    NSInteger index = [title rangeOfString:@":"].location;
    if(![Common isEmptyString:title])
    title = [title substringWithRange:NSMakeRange(index+1, title.length-index-1-1)];
    else
    title = NullString;
    
    noticeInfoViewController = nil;
    noticeInfoViewController = [[NoticeInfoViewController alloc] initWithNibName:@"NoticeInfoViewController" bundle:nil];
    noticeInfoViewController.delegate = self;
    noticeInfoViewController.screenId = currentScreenId;
    noticeInfoViewController.templateId = currentTemplateId;
    noticeInfoViewController.noticeInfoTitle = title;
    [self presentPopupViewController:noticeInfoViewController animationType:MJPopupViewAnimationFade];
    [self.noticeInfoButton setImage:[UIImage imageNamed:@"forscreen_messageclick.png"] forState:UIControlStateNormal];
}

- (IBAction)actionInfoAction:(id)sender {
   
    if ([allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"playFlag"] integerValue] == 1) {
        [[MBProgressController sharedInstance] showTipsOnlyText:@"流程正在播放" AndDelay:1.5];
        return;
    }
    
    if(actionInfoIndex == 0)
    {
        
        NSString *flowNodeId = [[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] objectAtIndex:StringFromId(allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"haveChooseNodeIndex"]).integerValue] objectForKey:@"id"];
        NSMutableDictionary *nodeDic = [NSMutableDictionary dictionary];
        for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeThumbnailArr"])
        {
            if([[dic allKeys] containsObject:flowNodeId])
            {
                nodeDic = [[dic objectForKey:flowNodeId] objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]];
                break;
            }
        }
        if([nodeDic[@"hostId"] isEqualToString:@""])
        {
            [[MBProgressController sharedInstance] showTipsOnlyText:@"画面未启动" AndDelay:1.5];
            return;
        }
        else if ([nodeDic[@"width"]isEqualToString:@""] ||
                 [nodeDic[@"height"]isEqualToString:@""])
        {
            [[MBProgressController sharedInstance] showTipsOnlyText:@"服务端此画面为空" AndDelay:1.5];
            [[MBProgressController sharedInstance] hide];
            return;
        }
        
//        CGFloat aceHeight = (Screen_Width-20)/([nodeDic[@"width"] intValue]/[nodeDic[@"height"] intValue]);
        
        self.aceDrawView = [[ACEDrawingView alloc] init];
        self.aceDrawView.frame = CGRectMake(0,0,(Screen_Width-20),390.0);
        self.aceDrawView.backgroundColor = [UIColor redColor];
       // self.aceDrawView.alpha = 0.5;
//        self.aceDrawView.backgroundColor = [UIColor clearColor];
        [self.aceDrawView setLineColor:ClearColor];
        [self.aceDrawView setLineWidth:0.0f];

        self.aceDrawView.zoomX = [nodeDic[@"width"] intValue]/(Screen_Width-20);
        self.aceDrawView.zoomY = [nodeDic[@"height"] intValue]/390.0;
        
        self.aceDrawView.screenWidth = [nodeDic[@"width"] intValue];
        self.aceDrawView.screenHeight = [nodeDic[@"height"] intValue];
        self.aceDrawView.doubleClickflag = YES;
//        self.aceDrawView.backgroundColor = [UIColor redColor];
        self.aceDrawView.forScreenFlag = NO;
        self.aceDrawView.drawingMode = DrawingModeNoneing;
        [self.aceDrawView configure];
        
        [self.allScreenInNote addSubview:self.aceDrawView];
         [self.allScreenInNote bringSubviewToFront:allBtn];
        [self.actionButton setImage:[UIImage imageNamed:@"forscreen_talkclick.png"] forState:UIControlStateNormal];
//        RootScreenView  *rootScreenView = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"];
//        [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"] addSubview:self.aceDrawView];
        
        NSInteger hostid = [nodeDic[@"hostId"] intValue];
        
        
        TcpClient *tcp = [TcpClient sharedInstance];
        if(!tcp.asyncSocket.isConnected)
        {
            [[MBProgressController sharedInstance] showTipsOnlyText:@"TCP连接出错" AndDelay:1.5];
            [[MBProgressController sharedInstance] hide];
            return;
        }
        dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            //[Common hostidtostring:hostid Metuod:@"GetEvents"]
            [tcp writeString:[Common hostidtostring:hostid Metuod:@"GetEvents"]];
        });
        actionInfoIndex = 1;
    }
    else
    {
        [self.aceDrawView removeFromSuperview];
        actionInfoIndex = 0;
        [self.actionButton setImage:[UIImage imageNamed:@"forscreen_talk.png"] forState:UIControlStateNormal];
        
    }
    
    
}


//双击处理:
- (void)handleDoubleTap:(UILongPressGestureRecognizer *)doubleTapSender
{
   [self.playInterval resignFirstResponder];
}
#pragma mark-
#pragma mark- NoticePopupDelegate
- (void)backButtonClicked:(NoticeInfoViewController *)noticeInfoController
{
    [self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationFade];
    noticeInfoController = nil;
        [self.noticeInfoButton setImage:[UIImage imageNamed:@"forscreen_message.png"] forState:UIControlStateNormal];
}

#pragma mark-
#pragma mark- AllNodesInScrollDelegate/TopLargerScreenViewDelegate

- (void)HandleTapNodeButton:(id)viewController ButtonIndex:(NSNumber *)num
{
    actionInfoIndex = 0;
    [self.aceDrawView removeFromSuperview];
    allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"haveChooseNodeIndex"] = num;//存放当前的Node Index;
    [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"topScreenView"] removeFromSuperview];
    NSString *flowNodeId = [[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] objectAtIndex:StringFromId(allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"haveChooseNodeIndex"]).integerValue] objectForKey:@"id"];
    for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeThumbnailArr"])
    {
        if([[dic allKeys] containsObject:flowNodeId])
        {
            allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"topScreenView"] = [[TopScreenView alloc] initWithFrame:CGRectMake(0, 0,[[dic objectForKey:flowNodeId] count]*100, 40)];
            break;
        }
    }
    NSMutableArray  *arr = [NSMutableArray array];
    NSMutableArray  *arrView = [NSMutableArray array];
    for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeThumbnailArr"])
    {
        if([[dic allKeys] containsObject:flowNodeId])
        {
            for(NSDictionary *nodeDic in [dic objectForKey:flowNodeId])
            {
                [arr addObject:[nodeDic objectForKey:@"name"]];
                [arrView addObject:[nodeDic objectForKey:@"templateId"]];
            }
            /*****************当前屏幕的screenId和templateId******************/
            currentScreenId = [[[dic objectForKey:flowNodeId] objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]] objectForKey:@"screenId"];
            currentTemplateId = [[[dic objectForKey:flowNodeId] objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]] objectForKey:@"templateId"];
            /***********************************/
            break;
        }
    }
    
    
    self.screenNameArr = [NSMutableArray arrayWithArray:arr];
    TopScreenView   *topScreenView = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"topScreenView"];
    topScreenView.delagateTopScreenForTap = self;
    topScreenView.nameArray = [NSArray arrayWithArray:arr];
    [self.allScreenTopView addSubview:topScreenView];
    [topScreenView initWithNameButtons];
    
    /********************每个节点的屏幕s****************************/
    [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"] removeFromSuperview];
    allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"] = [[RootScreenView alloc] initWithFrame:CGRectMake(10, 114,(Screen_Width-20), 430-40)];
    RootScreenView  *rootScreenView = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"];
    rootScreenView.viewNameArray = [NSArray arrayWithArray:arrView];
    [self.view insertSubview:rootScreenView belowSubview:self.allScreenInNote];
    [rootScreenView initWithViews:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]];
    /************************************************************/
}

#pragma mark-
#pragma mark- TopScreenViewDelegate

- (void)HandleTapScreenButton:(id)viewController ScreenIndex:(NSNumber *)num
{
    allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] = num;
    /********************每个节点的屏幕s****************************/
    actionInfoIndex = 0;
    [self.aceDrawView removeFromSuperview];
    [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"] removeFromSuperview];
    allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"] = [[RootScreenView alloc] initWithFrame:CGRectMake(10, 114,(Screen_Width-20), 430-40)];
    RootScreenView  *rootScreenView = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"rootScreenView"];
    
    NSMutableArray  *arrView = [NSMutableArray array];
    NSString *flowNodeId = [[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] objectAtIndex:StringFromId(allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"haveChooseNodeIndex"]).integerValue] objectForKey:@"id"];
    for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeThumbnailArr"])
    {
        if([[dic allKeys] containsObject:flowNodeId])
        {
            for(NSDictionary *nodeDic in [dic objectForKey:flowNodeId])
            {
                [arrView addObject:[nodeDic objectForKey:@"templateId"]];
            }
            /*****************当前屏幕的screenId和templateId******************/
            currentScreenId = [[[dic objectForKey:flowNodeId] objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]] objectForKey:@"screenId"];
            currentTemplateId = [[[dic objectForKey:flowNodeId] objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]] objectForKey:@"templateId"];
            /***********************************/
            break;
        }
    }
    
    rootScreenView.viewNameArray = [NSMutableArray arrayWithArray:arrView];
    [self.view insertSubview:rootScreenView belowSubview:self.allScreenInNote];
    [rootScreenView initWithViews:num.integerValue];
    /************************************************************/
}

#pragma mark-
#pragma mark- AllNodesInScrollDelegate

- (void)HandleNoteButtonLongPressPlay:(id)viewController ButtonID:(NSInteger)buttonIndex RECT:(CGRect) frame
{
    //    self.pannedView.frame = frame;
    [self NRLSMTFlowNodeAutoPlay:[[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] objectAtIndex:buttonIndex] objectForKey:@"id"] isTurn:@"true"];
}

- (void)HandlePausePlay:(id)viewController ButtonIndex:(NSNumber *)num
{
    if(num.integerValue == 1)
    {
        [self performSelector:@selector(oncePlayAction:) withObject:self.oncePlayButton];
    }
    else
    {
        [self performSelector:@selector(cyclesPlayAction:) withObject:self.cyclesPlayButton];
    }
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.playInterval resignFirstResponder];
}
//全屏
-(void)fullScreenClick:sender
{
    if(self.onceplayFlag || self.arrowplayFlag){
        return;
    }
    isFlowProjectPlay = YES;
    TopLargerScreenView *topLargerScr = allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"topLargerScr"];
    int largerScreenIndex = (int)(topLargerScr.contentOffset.x/(Screen_Width-20));
    int havePlayIndex = 0;
    if (isProjectScreen == YES)
    {
        havePlayIndex = [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"havePlayNodeIndex"]intValue];
    }
    else
    {
        havePlayIndex = [allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"havePlayNodeIndex"]intValue]-1;
    }
    if(largerScreenIndex == havePlayIndex)
        //投屏后
    {
        NSMutableDictionary *nodeDic = [NSMutableDictionary dictionary];
        
        NSString    *flowNameStr = self.flowNameLab.text;
        NSString    *nodeNameStr = [[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] objectAtIndex:havePlayIndex] objectForKey:@"name"];
        NSString    *screenNameStr = [self.screenNameArr objectAtIndex:0];
        NSString *flowNodeId = [[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] objectAtIndex:havePlayIndex] objectForKey:@"id"];
        for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeThumbnailArr"])
        {
            if([[dic allKeys] containsObject:flowNodeId])
            {
                nodeDic = [[dic objectForKey:flowNodeId] objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]];
                screenNameStr = [nodeDic objectForKey:@"name"];
                break;
            }
        }

        /**************画面未启动，不能给双击事件响应********************/
        if([nodeDic[@"hostId"]isEqualToString:@""])
        {
            [[MBProgressController sharedInstance] showTipsOnlyText:@"画面未启动" AndDelay:1.5];
            [[MBProgressController sharedInstance] hide];
            return;
        }
        else if ([nodeDic[@"width"]isEqualToString:@""] ||
                 [nodeDic[@"height"]isEqualToString:@""])
        {
            [[MBProgressController sharedInstance] showTipsOnlyText:@"加载画面缩略图失败" AndDelay:1.5];
            [[MBProgressController sharedInstance] hide];
            return;
        }
        /********************************************/
        NRLSVMForScreenViewController *playFlowNodes2ViewController = [[NRLSVMForScreenViewController alloc] initWithNibName:@"NRLSVMForScreenViewController" bundle:nil];
        playFlowNodes2ViewController.screenNum = [NSString stringWithFormat:@"%@%@%@",flowNameStr,@">",nodeNameStr];
        playFlowNodes2ViewController.hostId = nodeDic[@"hostId"];//[nodeDic[@"hostId"] intValue];
        playFlowNodes2ViewController.screenData = [NSMutableDictionary dictionaryWithDictionary:nodeDic];
        playFlowNodes2ViewController.forscreenId = currentScreenId;
        
        [self.navigationController presentViewController:playFlowNodes2ViewController animated:YES completion:nil];
    }
    else
    {
        NSString    *flowNameStr = self.flowNameLab.text;
        currentNodeName = [[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] objectAtIndex:StringFromId(allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"haveChooseNodeIndex"]).integerValue] objectForKey:@"name"];
        NSString    *screenNameStr = [self.screenNameArr objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]];
        NSString *flowNodeId = [[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"] objectAtIndex:StringFromId(allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"haveChooseNodeIndex"]).integerValue] objectForKey:@"id"];
        
        if(nodeNameArrForProject == nil)
        {
            nodeNameArrForProject = [NSMutableArray array];
            for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"])
            {
                [nodeNameArrForProject addObject:[dic objectForKey:@"name"]];
            }
        }
        else
        {
            [nodeNameArrForProject removeAllObjects];
            for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"receiveFlowDetailData"])
            {
                [nodeNameArrForProject addObject:[dic objectForKey:@"name"]];
            }
        }
        if(self.allNodeOneScreenArr == nil)
        {
            self.allNodeOneScreenArr = [NSMutableArray array];
        }
        else
        {
            [self.allNodeOneScreenArr removeAllObjects];
        }
        for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeThumbnailArr"])
        {
            for(NSMutableArray *arr in [dic objectEnumerator])
            {
                [self.allNodeOneScreenArr addObject:[arr objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]]];
            }
        }
        NSString    *templateIdForDisplay = nil;
        
        for(NSDictionary *dic in allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"nodeThumbnailArr"])
        {
            if([[dic allKeys] containsObject:flowNodeId])
            {
                NSDictionary *nodeDic = [[dic objectForKey:flowNodeId] objectAtIndex:[allFlowDataArr[lastFlowNumber][currentQueryingflowId][@"screenNo"] intValue]];
                templateIdForDisplay = [nodeDic objectForKey:@"templateId"];
                screenNameStr = [nodeDic objectForKey:@"name"];
                /**************画面未启动，不能给双击事件响应********************/
                if([nodeDic[@"hostId"]isEqualToString:@""])
                {
                    [[MBProgressController sharedInstance] showTipsOnlyText:@"画面未启动" AndDelay:1.5];
                    return;
                }
                else if ([nodeDic[@"width"]isEqualToString:@""] ||
                         [nodeDic[@"height"]isEqualToString:@""])
                {
                    [[MBProgressController sharedInstance] showTipsOnlyText:@"加载画面缩略图失败" AndDelay:1.5];
                    return;
                }
                /********************************************/
                break;
            }
        }
        NRLSVMAllScreenViewController *playFlowNodesViewController = [[NRLSVMAllScreenViewController alloc] initWithNibName:@"NRLSVMAllScreenViewController" bundle:nil];
        
        int i = 0;
        for(NSDictionary *dic in self.allNodeOneScreenArr)
        {
            if ([[dic objectForKey:@"templateId"] isEqualToString:templateIdForDisplay]) {
                playFlowNodesViewController.clickNum = i;//流程控制这边：clickNum:表示第几个节点
                break;
            }
            i++;
        }
        playFlowNodesViewController.arrData = [NSArray arrayWithArray:self.allNodeOneScreenArr];//arrData:存放某个流程中所有节点中，每个节点的某个屏幕的 一维数组
        playFlowNodesViewController.screenNum = flowNameStr;//
        playFlowNodesViewController.forscreenId = currentScreenId;//当前屏幕的id
        
        
        [self presentViewController:playFlowNodesViewController animated:YES completion:nil];
    }
}
@end
